<template>
  <ul class="todo-main">
    <todo-item v-for="(item,index) in todos" :key="index" :item="item" :index="index"/>
  </ul>
</template>

<script>
import {mapState} from 'vuex'
import TodoItem from "./TodoItem";
export default {
  name: "TodoLIst",
  computed:{
    /*高级写法 = $store.state.todos*/
    ...mapState(['todos'])
  },

  /*原有的监视函数移动到了这里*/
  watch:{ /*监视*/
    todos:{
      deep:true,
      handler:function (value){
        /*将todos的最新值保存*/
        window.localStorage.setItem('todos_key',JSON.stringify(value))
      }
    }
  },
  components:{
    TodoItem,
  },

}
</script>

<style scoped>


/*main*/
.todo-main {
  margin-left: 0px;
  border: 1px solid #ddd;
  border-radius: 2px;
  padding: 0px;
}

.todo-empty {
  height: 40px;
  line-height: 40px;
  border: 1px solid #ddd;
  border-radius: 2px;
  padding-left: 5px;
  margin-top: 10px;
}
</style>
